﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DARE.Save.DataStructures
{
    public class CSkyMgrData : ISaveData
    {

        public List<ASkyData> m_skies = new List<ASkyData>();
        public string m_activeSky;

        public void FillDataStructure(object skies)
        {
            CSkyMgr skyMgr = skies as CSkyMgr;
            foreach (ASky sky in skyMgr.GetAllSkies())
            {
                ASkyData s = CDataStructuresMgr.Instance.SaveItem(sky) as ASkyData;
                m_skies.Add(s);
            }
            if (skyMgr.ActiveSky != null)
                m_activeSky = skyMgr.ActiveSky.Name;
        }

        public void FillFromDataStructure(out object skyMgr, params object[] paramsData)
        {
            skyMgr = null;
            if (!(paramsData.Length > 0 && paramsData[0] is CRender3D))
                return;
            CSkyMgr sky = new CSkyMgr(paramsData[0] as CRender3D);

            foreach (ASkyData skyData in m_skies)
            {
                object s;
                skyData.FillFromDataStructure(out s, sky);
                sky.RegisterSky(s as ASky);
            }
            if (m_activeSky != null)
                sky.SetActiveSky(m_activeSky);
            skyMgr = sky;
        }
    }
}
